#include "stm32f10x.h"                  // Device header


uint16_t LED_Count;//???(??????)
void LED_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStruct;//??????????
	EXTI_InitTypeDef EXTI_InitStruct;
	NVIC_InitTypeDef NVIC_InitStruct;
	
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);  //??GPIO??
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);   //??AFIO??
	//EXTI ? NVIC????????,??????
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;     //????????,?????,??????????????,??????ST????GPIO?????(113?EXTI???)
	GPIO_InitStruct.GPIO_Pin = GPIO_Pin_14;
	GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; 
	GPIO_Init(GPIOB, &GPIO_InitStruct);
	//???,?AFIO??,??????GPIO?????
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource14);//?AFIO???????????
	
	//?????EXTI,???????
	EXTI_InitStruct.EXTI_Line = EXTI_Line14;//??PB14???14???;
	EXTI_InitStruct.EXTI_LineCmd = ENABLE;//????
	EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;//???????????
	EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;//????????
	EXTI_Init(&EXTI_InitStruct);
	
	//???,??NVIC(NVIC????,?????????misc.h???)
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//???????????(???????????????)
	NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;//?????????????,????????????????,??MD?????10-15EXTI???
	NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
	//?????,?????????,???????
	NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;  //???????
	NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1; //???????
	NVIC_Init(&NVIC_InitStruct);
	
}



//????????(?????startup???,????????10-15??)
void EXTI15_10_IRQHandler(void)//????????
{
	//???10-15EXTI???????????????EXTI14??????????1
	if(EXTI_GetITStatus(EXTI_Line14)== SET)
	{
			
			GPIO_InitTypeDef GPIO_InitStructure;	
			RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
			GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
			GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
			GPIO_Init(GPIOA,&GPIO_InitStructure);
		
		if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14)==Bit_RESET)//?????????????,?????
		{
			
			
			GPIO_SetBits(GPIOA,GPIO_Pin_5);
			//GPIO_ResetBits(GPIOA,GPIO_Pin_5);
		}
	    else if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14)==Bit_SET)
		{
		
			//GPIO_SetBits(GPIOA,GPIO_Pin_5);
			GPIO_ResetBits(GPIOA,GPIO_Pin_5);
		}
		
		
		//?????????????????,?????????,??????????
	EXTI_ClearITPendingBit(EXTI_Line14);
	}
	
}